<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta device="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
    <style>
      body {
        display: flex;
      }
      .box1,
      .box2 {
        width: 300px;
        height: 600px;
        border: 1px solid #ccc;
      }
      .box2 {
        margin-left: 50px;
      }

      .item {
        width: 100px;
        height: 50px;
        display: flex;
        justify-content: center;
        align-items: center;
        background-color: skyblue;
        margin-top: 10px;
        margin-left: 10px;
      }
    </style>
  </head>
  <body>
    <div class="box1">
      <div class="item" draggable="true" ondragstart="dragStart(event,'西瓜')">
        西瓜
      </div>
      <div class="item" draggable="true" ondragstart="dragStart(event,'芒果')">
        芒果
      </div>
      <div class="item" draggable="true" ondragstart="dragStart(event,'牛奶')">
        牛奶
      </div>
    </div>
    <div class="box2" ondrop="dropEnd(event)" ondragover="dragOver(event)"></div>

    <script>
      const box = document.querySelector('.box2')

      function dragStart(e, device) {
        console.log(e, device)
        e.dataTransfer.setData('device', device)
      }

      function dropEnd(e) {
        e.preventDefault() 
        console.log('box:', box)
        var msg = e.dataTransfer.getData('device')
        console.log('msg:', msg)
        const div = document.createElement('div')
        div.textContent = msg
        div.classList.add('item')
        box.appendChild(div)
      }

      function dragOver(e) {
        e.preventDefault()
      }
    </script>
  </body>
</html>
